package com.hex.ds.hdrs.cron.converter;

import cn.hutool.core.date.DateUtil;
import com.hex.ds.hdrs.common.constant.Const;
import com.hex.ds.hdrs.common.utils.BaseUtil;
import com.hex.ds.hdrs.cron.po.CronTask;
import com.hex.ds.hdrs.cron.po.CronTaskDef;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

@Mapper(componentModel = "spring", imports = {BaseUtil.class, DateUtil.class})
public interface ICronTaskConverter {

    @Mappings({
            @Mapping(target = "pkId", expression = "java(BaseUtil.getPkId())"),
            @Mapping(target = "crtTs", expression = "java(DateUtil.now())"),
            @Mapping(target = "execStTs", expression = "java(DateUtil.now())"),
            @Mapping(target = "upTs", expression = "java(DateUtil.now())"),
            @Mapping(target = "execStatus", constant = Const.CRON_TASK_EXEC_STATUS_EXECING)
    })
    CronTask toCronTask(CronTaskDef cronTaskDef);
}
